package cn.lblbc.downloadlib.database;

import androidx.room.Dao;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;
import androidx.room.Update;

import java.util.List;

@Dao
public interface DownloadFileDao {
    @Query("SELECT * FROM download_files WHERE task_id = :taskId")
    List<DownloadFileEntity> getFilesByTaskId(long taskId);

    @Query("SELECT * FROM download_files WHERE file_id = :fileId")
    DownloadFileEntity getFileById(long fileId);

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    void insertFile(DownloadFileEntity file);

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    void insertFiles(List<DownloadFileEntity> files);

    @Update
    void updateFile(DownloadFileEntity file);

    @Query("DELETE FROM download_files WHERE task_id = :taskId")
    void deleteFilesByTaskId(long taskId);

    @Query("DELETE FROM download_files WHERE file_id = :fileId")
    void deleteFile(long fileId);

    @Query("UPDATE download_files SET status = :status, update_time = :updateTime WHERE file_id = :fileId")
    void updateFileStatus(long fileId, int status, long updateTime);

    @Query("UPDATE download_files SET downloaded_size = :downloadedSize, update_time = :updateTime WHERE file_id = :fileId")
    void updateFileProgress(long fileId, long downloadedSize, long updateTime);
}